package net.ryian.push;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

import org.apache.log4j.Logger;

public class PushConfig {

	protected static final Logger logger = Logger.getLogger(PushConfig.class);
	public static PushConfig INSTANCE = new PushConfig();

	private Properties prop;

	protected PushConfig() {
		prop = new Properties();
		try {
			prop.load(new InputStreamReader(this.getClass().getClassLoader()
					.getResourceAsStream("push.properties"), "UTF-8"));
		} catch (IOException e) {
			logger.error(e);
		}
	}

	public boolean getValue(String key, boolean defaultVal) {
		String s = prop.getProperty(key);
		if (s == null)
			return defaultVal;
		else
			return Boolean.parseBoolean(s);
	}

	public String getValue(String key, String defaultVal) {
		String s = prop.getProperty(key);
		if (s == null || s.trim().equals(""))
			return defaultVal;
		else
			return s;
	}

	public boolean isDevmode() {
		return getValue("devmode", false);
	}

	public String getPushImpl() {
		return getValue("push.impl", "baidu");
	}
}
